<template>
  <div>
    <el-drawer
      :with-header="false"
      :size="1000"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
    >
      <div v-loading="loading">
        <div class="head">
          <div class="full">
            <img class="order_icon" :src="orderImg" alt="" />
            <div class="text">
              <div class="title">酒店订单</div>
              <div>
                <span class="mr20">订单编号：{{ orderDetailList.order_no }}</span>
              </div>
            </div>
            <div >
          
              <el-button
                v-if="orderDetailList.pay_status == 1"
                type="success"
                size="small"
                @click="onOrderMark"
                >订单备注</el-button
              >
           
            </div>
          </div>
          <ul class="list">
            <li class="item">
              <div class="title">订单状态</div>
              <div>
                <div  class="value1">
                  <span>{{ orderDetailList.order_status | hotelOrderStatusFilter }}</span>
                </div>
               
              </div>
            </li>
            <li class="item">
              <div class="title">实际支付</div>
              <div>¥ {{ orderDetailList.pay_amount }}</div>
            </li>
            <li class="item">
              <div class="title">支付方式</div>
              <div v-if="orderDetailList.pay_satus == 1">{{ orderDetailList.pay_type | payTypeFilter }}</div>
              <div v-else>未支付</div>
            </li>
            <li class="item">
              <div class="title">支付时间</div>
              <div>{{ orderDetailList.create_time }}</div>
            </li>
          </ul>
        </div>
        <el-tabs type="border-card" v-model="activeName" @tab-click="tabClick">
          <el-tab-pane label="订单信息" name="detail">
            <template v-if="activeName == 'detail'">
              <div class="section">
                <div class="title">用户信息</div>
                <ul v-if="orderDetailList.user" class="list">
                  <li class="item">
                    <div>用户昵称：</div>
                    <div class="value">
                      {{
                        orderDetailList.user.real_name ? orderDetailList.user.real_name : orderDetailList.user.nickname
                      }}
                    </div>
                  </li>
                  <li class="item">
                    <div>用户ID：</div>
                    <div class="value">{{ orderDetailList.user.uid ? orderDetailList.user.uid : '-' }}</div>
                  </li>
                  <li class="item">
                    <div>绑定电话：</div>
                    <div class="value">{{ orderDetailList.user.phone ? orderDetailList.user.phone : '-' }}</div>
                  </li>
                </ul>
              </div>
             
             
              <div class="section">
                <div class="title">订单信息</div>
                <ul class="list">
                   <li class="item">
                    <div>产品信息：</div>
                    <div class="value" v-if="orderDetailList.hotelRoomType">{{  orderDetailList.hotelRoomType.name + ' | '  + orderDetailList.hotelRoomPackage.name }}</div>
                  </li> 
                   <li class="item">
                    <div>入住日期：</div>
                    <div class="value">{{  orderDetailList.check_in_date + ' / '+ orderDetailList.check_out_date}}</div>
                  </li> 
                   <li class="item">
                    <div>入住天数：</div>
                    <div class="value">{{  orderDetailList.nights }}</div>
                  </li> 
                  <li class="item">
                    <div>房间总数：</div>
                    <div class="value">{{ orderDetailList.room_count ? orderDetailList.room_count : '-' }}</div>
                  </li>
                  <li class="item">
                    <div>实际支付：</div>
                    <div class="value">{{ orderDetailList.pay_amount ? (parseFloat(orderDetailList.pay_amount) ) : orderDetailList.pay_amount }}</div>
                  </li>
                  <li class="item">
                    <div>优惠券金额：</div>
                    <div class="value">{{ orderDetailList.discount_amount ? orderDetailList.discount_amount : '-' }}</div>
                  </li>
             
                  <li class="item">
                    <div>订单总价：</div>
                    <div class="value">{{ orderDetailList.total_amount ? orderDetailList.total_amount : '-' }}</div>
                  </li>
                   <li class="item">
                    <div>创建时间：</div>
                    <div class="value">{{ orderDetailList.create_time ? orderDetailList.create_time : '-' }}</div>
                  </li>
                </ul>
              </div>
      
              <div class="section">
                <div class="title">买家留言</div>
                <ul class="list">
                  <li class="item">
                    <div>{{ orderDetailList.remark ? orderDetailList.remark : '-' }}</div>
                  </li>
                </ul>
              </div>
              <div class="section">
                <div class="title">商家备注</div>
                <ul class="list">
                  <li class="item">
                    <div>{{ orderDetailList.mer_mark ? orderDetailList.mer_mark : '-' }}</div>
                  </li>
                </ul>
              </div>
               <div class="section">
                <div class="title">平台备注</div>
                <ul class="list">
                  <li class="item">
                    <div>{{ orderDetailList.admin_mark ? orderDetailList.admin_mark : '-' }}</div>
                  </li>
                </ul>
              </div>
            </template>
            
          </el-tab-pane>
      
          <el-tab-pane v-if="orderDetailList.room_name_list" label="入住客人" name="storeOrderPassenger">
            <el-table :data="orderDetailList.room_name_list" size="small">
              <el-table-column prop="passenger" label="房间" min-width="200">
                <template slot-scope="scope">
                  <span>房间{{ scope.row.roomKey }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="passenger" label="姓名" min-width="200">
                <template slot-scope="scope">
                  <span>{{ scope.row.roomName }}</span>
                </template>
              </el-table-column>
           
            </el-table>
            <div class="block">
              <el-pagination :page-size="tableFromLog.limit" :current-page="tableFromLog.page" layout="prev, pager, next, jumper" :total="tableDataLog.total" @size-change="handleSizeChangeLog" @current-change="pageChangeLog" />
            </div>
          </el-tab-pane>
          <el-tab-pane label="订单记录" name="orderList">
            <div v-if="activeName == 'orderList'">
              <el-form size="small" label-width="90px">
                <div class="acea-row">
                  <el-form-item label="操作端：" class="mr10">
                    <el-select
                      v-model="tableFromLog.user_type"
                      placeholder="请选择"
                      class="selWidth"
                      clearable
                      filterable
                      @change="onOrderLog(orderId)"
                    >
                      <el-option label="系统" value="0" />
                      <el-option label="用户" value="1" />
                      <el-option label="平台" value="2" />
                      <el-option label="商户" value="3" />
                      <el-option label="商家客服" value="4" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="操作时间：">
                    <el-date-picker
                      class="selWidth"
                      v-model="timeVal"
                      type="datetimerange"
                      placeholder="选择日期"
                      value-format="yyyy/MM/dd HH:mm:ss"
                      clearable
                      @change="onchangeTime"
                    >
                    </el-date-picker>
                  </el-form-item>
                  <!-- <div>
                    <el-button type="primary" size="small" @click="onOrderLog(orderId)">查询</el-button>
                  </div> -->
                </div>
              </el-form>
            </div>
            <el-table :data="tableDataLog.data" size="small">
              <el-table-column prop="order_id" label="订单编号" min-width="200">
                <template slot-scope="scope">
                  <span>{{ scope.row.order_sn }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作记录" min-width="200">
                <template slot-scope="scope">
                  <span>{{ scope.row.change_message }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作角色" min-width="150">
                <template slot-scope="scope">
                  <div class="tab">
                    <div>{{ operationType(scope.row.user_type) }}</div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="操作人" min-width="150">
                <template slot-scope="scope">
                  <div class="tab">
                    <div>{{ scope.row.nickname }}</div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="操作时间" min-width="150">
                <template slot-scope="scope">
                  <div class="tab">
                    <div class="line1">{{ scope.row.change_time }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="block">
              <el-pagination :page-size="tableFromLog.limit" :current-page="tableFromLog.page" layout="prev, pager, next, jumper" :total="tableDataLog.total" @size-change="handleSizeChangeLog" @current-change="pageChangeLog" />
            </div>
          </el-tab-pane>
      
        </el-tabs>
      </div>
    </el-drawer>

  </div>
</template>
<script>


import {
  orderRemarkApi,
  hotelOrderStatusApi,
  hotelOrderDetailApi,
} from '@/api/product';


export default {
  props: {
    drawer: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      loading: true,
      orderId: '',
      direction: 'rtl',
      activeName: 'detail',
      goodsList: [],
      orderConfirm: false,
      sendGoods: false,
      dialogLogistics: false,
      confirmReceiptForm: {
        id: '',
      },
      orderData: [],
      contentList: [],
      nicknameList: [],
      result: [],
      timeVal: [],
      childOrder: [],
      childOrder: [],
      tableDataLog: {
        data: [],
        total: 0
      },
      tableFromLog: {
        user_type: '',
        date: [],
        page: 1,
        limit: 10
      },
      orderDetailList: {
        user: {
          real_name: '',
        },
        groupOrder: {
          group_order_sn: '',
        },
      },
      orderImg: require('@/assets/images/order_icon.png'),

    };
  },
  filters: {
  },
  methods: {
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e
      this.tableFromLog.date = e ? this.timeVal.join('-') : ''
      this.onOrderLog(this.orderId)
    },
    handleClose() {
      this.activeName = 'detail';
      this.$emit('closeDrawer');
      this.sendGoods = false;
      this.orderRemark = false;
    },
  
    
   
      // 备注
    onOrderMark() {
      this.$modalForm(orderRemarkApi(this.orderId)).then(() => this.getInfo(this.orderId))
    },
 
    getInfo(id) {
      this.loading = true;
      this.orderId = id
      hotelOrderDetailApi(id)
        .then((res) => {
          this.drawer = true;
          this.orderDetailList = res.data;
          this.loading = false;
        })
        .catch((res) => {
          this.$message.error(res.message);
            this.loading = false;
        });
    },
    tabClick(tab) {
      if (tab.name === 'orderList') {
       this.onOrderLog(this.orderId)
      }
    },
    onOrderLog(id){
      hotelOrderStatusApi(id, this.tableFromLog).then((res) => {
        this.tableDataLog.data = res.data.list
        this.tableDataLog.total = res.data.count
      });
    },
    pageChangeLog(page) {
      this.tableFromLog.page = page
      this.onOrderLog(this.orderId)
    },
    handleSizeChangeLog(val) {
      this.tableFromLog.limit = val
      this.onOrderLog(this.orderId)
    },
    operationType(type) {
      if (type == 0) {
        return '系统';
      } else if (type == 1) {
        return '用户';
      } else if (type == 2) {
        return '平台';
      } else if (type == 3) {
        return '商户';
      } else if (type == 4) {
        return '商家客服';
      } else {
        return '未知';
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.head {
  padding: 20px 20px 10px;
  .full {
    display: flex;
    align-items: center;
    .order_icon {
      width: 60px;
      height: 60px;
    }
    .iconfont {
      color: var(--prev-color-primary);
      &.sale-after {
        color: #90add5;
      }
    }
    .text {
      align-self: center;
      flex: 1;
      min-width: 0;
      padding-left: 12px;
      font-size: 13px;
      color: #606266;
      .title {
        margin-bottom: 10px;
        font-weight: 500;
        font-size: 16px;
        line-height: 16px;
        color: rgba(0, 0, 0, 0.85);
      }
      .order-num {
        padding-top: 10px;
        white-space: nowrap;
      }
    }
  }
  .list {
    display: flex;
    margin-top: 20px;
    overflow: hidden;
    list-style: none;
    padding: 0;
    .item {
      flex: none;
      width: 200px;
      font-size: 14px;
      line-height: 14px;
      color: rgba(0, 0, 0, 0.85);
      .title {
        margin-bottom: 12px;
        font-size: 13px;
        line-height: 13px;
        color: #666666;
      }
      .value1 {
        color: #f56022;
      }
      .value2 {
        color: #1bbe6b;
      }
      .value3 {
        color: #437FFD;
      }
      .value4 {
        color: #6a7b9d;
      }
      .value5 {
        color: #f5222d;
      }
    }
  }
}
.el-tabs--border-card {
  box-shadow: none;
  border-bottom: none;
}
.section {
  padding: 20px 0 8px;
  border-bottom: 1px dashed #eeeeee;
  .title {
    padding-left: 10px;
    border-left: 3px solid var(--prev-color-primary);
    font-size: 15px;
    line-height: 15px;
    color: #303133;
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
  }
  .item {
    flex: 0 0 calc(100% / 3);
    display: flex;
    margin-top: 16px;
    font-size: 13px;
    color: #606266;

    &:nth-child(3n + 1) {
      padding-right: 20px;
    }

    &:nth-child(3n + 2) {
      padding-right: 10px;
      padding-left: 10px;
    }

    &:nth-child(3n + 3) {
      padding-left: 20px;
    }
  }
  .value {
    flex: 1;
    image {
      display: inline-block;
      width: 40px;
      height: 40px;
      margin: 0 12px 12px 0;
      vertical-align: middle;
    }
  }
}
.tab {
  display: flex;
  align-items: center;
  .el-image {
    width: 36px;
    height: 36px;
    margin-right: 10px;
  }
}
::v-deep .el-drawer__body {
  overflow: auto;
}
.gary {
  color: #aaa;
}
.logistics{
  align-items: center;
  padding: 10px 0px;
  .logistics_img{
    width: 45px;
    height: 45px;
    margin-right: 12px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .logistics_cent{
    span{
      display: block;
      font-size: 12px;
    }
  }
}
.tabBox_tit {
  width: 53%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
</style>
